<?php
namespace app\admin\controller;
use think\Controller;

class Login extends controller{
    function index(){
		return $this->fetch();
	}
	function logout(){
		model('user')->where('id',session('adminid'))->update(['status'=>0]);
		session(null);
		$this->redirect("admin/index/index");
	}
	function sta(){
		$result = model('user')->ss(session('adminid'));
		if($result['tiren']==0){
			model('user')->where('id',session('adminid'))->update(['status'=>0]);
			return false;
		}
		return true;
	}
	function login($code){
		if(!captcha_check($code)){
			 //验证失败
			$this->error('验证码错误');
			}
		$username = $_POST['un'];
		$password = $_POST['pw'];
		$judge = Model("User")->findall($username,$password);
		if($judge == true){
			if($judge["tiren"]==1){
				session('admin',$username);
				session('adminid',$judge['id']);
				session('usertype',$judge['types']);
				session('roots',$judge['roots']);
				$last = $judge["intime"];
				$n = $judge['numbers'];
				$n++;
				$userip = request()->ip();
				model('user')->where('id',session('adminid'))->update(['numbers'=>$n,'intime'=>time(),'last_time'=>$last,"ipaddrs"=>$userip,'status'=>1]);
				$this->redirect("admin/home/index");
				exit;
			}
			$this->redirect("admin/index/index");
			exit();
		}
		$this->error("登录信息错误!");
	}
}
